package tool;
/*
@Date:2025/3/25
*/

import dao.Dao;
import dao.VisitInterface;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.apache.log4j.PropertyConfigurator;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Get {
    public static SqlSession getsqlSession() throws Exception {
        //读取mybatis配置文件
        final InputStream resourceAsStream = Resources.getResourceAsStream("config/mybatis-config.xml");
        //获取sqlsession工厂对象
        final SqlSessionFactory build = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //通过工厂获取对像
        final SqlSession sqlSession = build.openSession();

        return  sqlSession;
    }

    public static  VisitInterface getmapper(SqlSession sqlSession,Class<VisitInterface> c) throws IOException {
        // 获取映射接口的实例
        final VisitInterface mapper = sqlSession.getMapper(c);
        return mapper;
    }
    public static  void getpropertiy() throws IOException {
        //输出查询过程信息
        final Properties properties = new Properties();
        final FileInputStream fileInputStream = new FileInputStream("src/main/resources/config/log4j.properties");
        properties.load(fileInputStream);
        PropertyConfigurator.configure(properties);
    }
}
